function switchNightMode() {
    if(localStorage.getItem("dark") == "true"){
        localStorage.setItem('dark', false);
        switchToLight(); 
        return;
    }
    else {
        localStorage.setItem('dark', true);
        switchToDark();
        return;
    }
}
function switchToDark()
{
    var links = document.getElementsByTagName("link");
    for (var i = 0; i < links.length; i++) {
        // console.log(links[i].href);
        if (links[i] && links[i].href && links[i].href.indexOf("/css/style.css") != -1){
            // console.log("change.");
            links[i].setAttribute("href","/css/style-dark.css");
        }
    }
}

function switchToLight()
{
    var links = document.getElementsByTagName("link");
    for (var i = 0; i < links.length; i++) {
        // console.log(links[i].href);
        if (links[i] && links[i].href && links[i].href.indexOf("/css/style-dark.css") != -1){
            // console.log("change.");
            links[i].setAttribute("href","/css/style.css");
        }
    }
}

(function(){//console.log("dark = ", localStorage.getItem("dark"));
    if (localStorage.getItem == "null"){
        localStorage.setItem("dark", true);
    }
    if (localStorage.getItem("dark") == "true"){
        // console.log("a");
        switchToDark();
    } else {
        // console.log("b");
        switchToLight();
    }
    })();
    
    


